import {
  colorUISdk
} from "../../config/mp-sdk";
import {updateCurrentPageShare} from "../../mp-sdk/lib/share";

const app = getApp();
let interstitialAd = null
Page({
  data: {
    scrollTop: 0,
    target:'',
    phoneNumber: "13526264379",
    swiperList: [{
        img: "/static/img/45fc.png"
      },
      {
        img: "/static/img/d0f2.png"
      }
    ],
    helpList:[],
    modalBox:{
      target:'',
    },
  },
  callPhone() {
    wx.makePhoneCall({
      phoneNumber: '13526264379' //仅为示例，并非真实的电话号码
    });
  },

  subscribe() {
    wx.requestSubscribeMessage({
      tmplIds: ['nGA2V4J7bVeuKS7xiu4RsAsw91BEB45N13sJ_VNpQmQ'], // 替换为你的模板ID
      success(res) {
        console.log('订阅结果：', res);
        if (res['nGA2V4J7bVeuKS7xiu4RsAsw91BEB45N13sJ_VNpQmQ'] === 'accept') {
          wx.showToast({ title: '订阅成功', icon: 'success' });
          // 可以调用后端接口通知已授权（可选）
        } else {
          wx.showToast({ title: '用户拒绝了订阅', icon: 'none' });
        }
      },
      fail(err) {
        console.error('订阅失败：', err);
      }
    });
  },


  onLoad(options) {
    //获取帮助列表
    //this.getHelpList();

  },

  onShow() {
    //获取帮助列表
    this.getHelpList();
  },
  //获取帮助列表
  getHelpList(){
    colorUISdk.request({
      url: 'api/help/list',
      method: 'GET',
      data: {}
    }).then(res => {
      //判断
      if (res.code === 1){
        this.setData({
          helpList:res.data
        });
        // 登录成功后立即更新分享配置
        updateCurrentPageShare();
      }
    }).catch(err => {
      console.log(err)
    })

  },


  helpDetail(e) {
    let id = e.currentTarget.dataset.id;
    //获取help详情
    let item = this.data.helpList.find(item => item.id === id);


    this.setData({
      modalBox: {
        target: 'drawer',
        title: item.problem,
        content: item.answer,
        video: item.video,
        video_url: item.video_url,
      }
    })

    //跳转到详情页
    this.setData({
      target: "drawer"
    })
  },
  showCall(e) {
    let res = e.detail;
    if (res.confirm) {
      this.callPhone();
    }
  },
  success(res) {
    const {
      detail
    } = res
    console.log(detail);
  },
  showCustomizeModal(e) {
    this.setData({
      target: e.currentTarget.dataset.key
    })
  },
  // 监听用户滑动页面事件。
  onPageScroll(e) {
    this.setData({
      scrollTop: e.scrollTop
    })
  },
})